import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutterflow_ui/flutterflow_ui.dart';
import 'package:get/get.dart';

import '../../../dd_core/dd_http.dart';
import '../../../dd_core/dd_user_service.dart';
import '../../../dd_models/dd_goods_model.dart';
import '../../../dd_models/dd_oauth_model.dart';

class DDCoinShopController extends GetxController {
  //final authModel = DDOauthModel().obs;

  final googsObx = <DDGoodsModel>[].obs;

  final availableCoins = Get.find<DDUserService>().availableCoins;

  @override
  onInit() {
    super.onInit();
    goodsSearchApi();
  }

  @override
  void onClose() {
    googsObx.close();
  //  authModel.close();
  //  availableCoins.close();
    super.onClose();
  }

  goodsSearchApi() async {
    EasyLoading.show();
    Map<String, dynamic>? result = await goodsSearch();
    EasyLoading.dismiss();
    if (result != null && result['code'] == 0) {
      List<DDGoodsModel> goods = [];
      goods = (result['data'] as List)
          .map((json) => DDGoodsModel.fromJson(json))
          .toList();
      googsObx.value = goods;
      googsObx.refresh();
    }
  }

}
